using System;
using GameOfLifeX.Core;
using System.Diagnostics;
using System.Threading.Tasks;

namespace GameOfLifeX.Console
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			const int modelWidth = 200;
			const int modelHeight = 200;
			const int generationsToRun = 100;

			var newModel = new GameOfLifeModel (modelWidth, modelHeight);
			newModel.SeedRandomly ();

			var model = new Model (modelWidth, modelHeight);
			model.SeedRandomly ();
		


			RunSync (model, generationsToRun);	
			RunSyncNewModel (newModel, generationsToRun);
					
		}	

		static void RunSync (Model model, int generationsToRun)
		{
			var sw = Stopwatch.StartNew ();
			for (int i = 0; i < generationsToRun; i++)
				model.RunGeneration ();

			var elapsed = sw.Elapsed;
			var generationsPerSecond = generationsToRun / elapsed.TotalSeconds;
			System.Console.WriteLine ("Sync Generations Per Second: " + generationsPerSecond.ToString ());
		}

		static void RunSyncNewModel (GameOfLifeModel model, int generationsToRun)
		{
			var sw = Stopwatch.StartNew ();
			for (int i = 0; i < generationsToRun; i++)
				model.RunGeneration ();

			var elapsed = sw.Elapsed;
			var generationsPerSecond = generationsToRun / elapsed.TotalSeconds;
			System.Console.WriteLine ("NEW MODEL: Sync Generations Per Second: " + generationsPerSecond.ToString ());
		}

		static void RunSyncWithInternalParallel (Model model, int generationsToRun)
		{
			var sw = Stopwatch.StartNew ();
			for (int i = 0; i < generationsToRun; i++)
				model.RunGenerationParallel ();

			var elapsed = sw.Elapsed;
			var generationsPerSecond = generationsToRun / elapsed.TotalSeconds;
			System.Console.WriteLine ("Sync Generations with internal Parallel Per Second: " + generationsPerSecond.ToString ());
		}
	}
}
